package rdd

import org.apache.spark.util.LongAccumulator
import org.apache.spark.{SparkConf, SparkContext}

object RDD_AccumulatorsTest {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("RDD_AccumulatorsTest")

    val sc = new SparkContext(conf)
    val acc: LongAccumulator = sc.longAccumulator("My Accumulators")

    sc
      .parallelize(List(1,2,3,4))
      .foreach(
        x => acc.add(x)
      )

    println(acc.value)


    sc.stop()
  }
}
